package com.chemical.search.view.manage;
/**
 *@className:UploadAction.java
 *@classDescription:
 *@author:MChen
 *@createTime:2012-7-3
 */
import java.io.File;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.chemical.search.model.BaseAttribute;

@Controller
public class UploadAction {

    @RequestMapping(value = "/upload")
    public String upload(@RequestParam(value = "file1", required = false) MultipartFile file1,
    		@RequestParam(value = "file2", required = false) MultipartFile file2,
    		BaseAttribute att, HttpServletRequest request, ModelMap model) {
    	System.out.println(att.getName_cn()+"===="+att.getName_en()+"===="+att.getCas_rn());
        System.out.println("开始");
        String path = request.getSession().getServletContext().getRealPath("upload");
        System.out.println(path);
        String fileName1 = file1.getOriginalFilename();
        String fileName2 = file2.getOriginalFilename();
        System.out.println(fileName1+"===="+fileName2);
        String fileName = new Date().getTime()+".jpg";
        System.out.println(fileName);
        File targetFile = new File(path, fileName1);
        if(!targetFile.exists()){
            targetFile.mkdirs();
        }
        File targetFile2 = new File(path, fileName2);
        if(!targetFile2.exists()){
            targetFile2.mkdirs();
        }

        //保存
        try {
            file1.transferTo(targetFile);
            file2.transferTo(targetFile2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        model.addAttribute("fileUrl", request.getContextPath()+"/upload/"+fileName1);

        return "result.jsp";
    }

}
